#include "led_control.h"
#include <stdio.h>
#include "los_task.h"
#include "iot_gpio.h"

/* GPIO定义 */
#define GPIO_LED GPIO0_PA5

/* 全局变量 */
extern volatile uint8_t g_human_detected;
volatile uint8_t g_led_state = 0;

void led_control_task(void *arg)
{
    /* 初始化LED GPIO */
    (void)IoTGpioInit(GPIO_LED);
    (void)IoTGpioSetDir(GPIO_LED, IOT_GPIO_DIR_OUT);
    
    while (1) {
        if (g_human_detected) {
            /* 人体检测模式：LED保持常亮 */
            if (!g_led_state) {
                (void)IoTGpioSetOutputVal(GPIO_LED, IOT_GPIO_VALUE1);
                g_led_state = 1;
            }
        } else {
            /* 正常模式：LED 0.5秒闪烁 */
            g_led_state = !g_led_state;
            (void)IoTGpioSetOutputVal(GPIO_LED, g_led_state);
        }
        (void)LOS_Msleep(500);
    }
}
